<?php

namespace App\Support;

use App\Models\ProjectAgreement;

class Data
{

    public static function getNoticeType($id)
    {
        $type = [
            '1' => '完善服务信息',
            '2' => '支付提醒',
            '3' => '资料补充',
            '4' => '沟通记录',
            '5' => '投稿系统注册信息',
            '6' => '投稿邮箱提醒',
            '7' => '新订单提醒',
            '8' => '投稿进度',
        ];
        if (isset($id) & !empty($id)) {
            return $type[$id];
        } else {
            return $type;
        }
    }


    /**
     * 返回控制器图标.
     *
     * @param $string
     *
     * @return string
     */
    public static function icon($string): string
    {
        $array = [
            'record' => '<i class="fa feather icon-list"></i> ',
            'category' => '<i class="fa feather icon-pie-chart"></i> ',
            'track' => '<i class="fa feather icon-archive"></i> ',
            'issue' => '<i class="fa feather icon-alert-triangle"></i> ',
            'user' => '<i class="fa feather icon-users"></i> ',
            'department' => '<i class="fa feather icon-copy"></i> ',
            'role' => '<i class="fa feather icon-users"></i> ',
            'permission' => '<i class="fa feather icon-lock"></i> ',
            'statistics' => '<i class="fa feather icon-bar-chart-2"></i> ',
            'column' => '<i class="fa feather icon-edit-2"></i> ',
            'history' => '<i class="fa feather icon-clock"></i> ',
        ];

        return $array[$string];
    }



    /**
     * 返回时间尺度.
     *
     * @return string[]
     */
    public static function timeScales(): array
    {
        return [
            'day' => '天',
            'month' => '月',
            'year' => '年',
        ];
    }
    /**
     * 成功或失败.
     *
     * @return string[]
     */
    public static function successOrFail(): array
    {
        return ['失败', '成功'];
    }

    /**
     * 获取订单状态
     *
     * @Author hechengwei
     * @email chichiooo@sina.com
     * @DateTime 2023-12-06
     * @return array
     */
    public static function getOrderStatus(): array
    {
        return [
            0 => '待支付',
            1 => '已支付',
            2 => '已完成',
            -1 => '已取消',
        ];
    }

    /**
     * 获取支付状态
     *
     * @Author hechengwei
     * @email chichiooo@sina.com
     * @DateTime 2023-12-06
     * @return array
     */
    public static function getPayStatus(): array
    {
        return [0 => '未支付', 1 => '已支付'];
    }

    /**
     * 获取支付类型
     *
     * @Author hechengwei
     * @email chichiooo@sina.com
     * @DateTime 2023-12-06
     * @return array
     */
    public static function getPayType(): array
    {
        return ['alipay' => '支付宝', 'wechat' => '微信', 'bank' => '银行卡'];
    }

    /**
     * 获取订单服务信息
     *
     * @Author hechengwei
     * @email chichiooo@sina.com
     * @DateTime 2023-12-06
     * @return array
     */
    public static function getOrderService(): array
    {
        return [
            1 => '妥投报告',
            2 => '优质润色',
            3 => '学术翻译',
            4 => '图表优化',
            5 => '期刊格式调整与指导服务',
            6 => '投稿信撰写',
            7 => '回复信/接受信撰写',
            8 => '全程无忧套餐',
            9 => '投稿协助',
        ];
    }


    /**
     * 获取订单稿件用途
     *
     * @Author hechengwei
     * @email chichiooo@sina.com
     * @DateTime 2023-12-06
     * @return array
     */
    public static function getOrderPurpose(): array
    {
        return [
            0 => '请选择',
            1 => '研究报告/期刊论文',
            2 => '摘要',
            3 => '案例报告',
            4 => '会议论文',
            5 => '硕士/博士论文',
            6 => '其他（学术类）',
            7 => '图书出版',
            8 => '同行评审意见',
            9 => '回复评审意见',
            10 => '其他（非学术类）',
            11 => '演讲稿/海报',
            12 => '信件/电子邮件',
            13 => '经费申请',
            14 => '网站内容',
            15 => '年度报告',
            16 => '演讲稿/致辞',
            17 => '市场/促销材料',
        ];
    }

    public static function getSbumitDetails()
    {
        return [
            1 => '投稿详情',
            2 => '补充资料',
        ];
    }

    public static function getMessageTemplate()
    {
        return [
            1 => '信息确认模板',
            2 => '前期沟通模板',
        ];
    }


    public static function getOrderSn()
    {
        return randSole(0, 8);
    }

    public static function getRegion()
    {
        return [
            0 => '全区',
            1 => '东区',
            2 => '南区',
            3 => '西区',
            4 => '北区',
            5 => '中区',
        ];
    }


    /**
     * 获取税率和税前金额
     *
     * @Author hechengwei
     * @email chichiooo@sina.com
     * @DateTime 2024-04-26
     * @param [type] $afterTaxAmount   税后金额
     * @return void
     */
    public static function getTaxRate($afterTaxAmount)
    {
        // ROUND(
        //     @IF(
        //         A2<=800,
        //         0,// true 如果小于等于 800 没有税
        //         IF( // false  否则判断
        //             A2<=3360, //条件 是否小于等于 3360
        //             (A2-800)/4,//true 如果小于等于 3360  (税后收入-800) /4 就是税
        //             IF( // false 否则判断
        //                 A2<=21000, // 条件 税后收入是否小于等于21000
        //                 0.16*A2/0.84, // true 如果小于等于 21000  0.16*税后收入/0.84
        //                 IF( // false 否则判断
        //                     A2<=49500, // 条件 税后收入是否小于等于49500
        //                     (0.24*A2-2000)/0.76, // true 如果小于等于 49500  (0.24*税后收入-2000)/0.75 等于税
        //                     (0.32*A2-7000)/0.68) // false 否则大于49500  (0.32*税后收入-7000)/0.68
        //                     ))
        //     )
        //     ,2 // 四舍五入保留两位小数
        //     )
        // $afterTaxAmount = round($afterTaxAmount, 2);
        // $afterTaxAmount = number_format($afterTaxAmount, 2, '.', '');
        if ($afterTaxAmount <= 800) {
            // 税率  税后金额
            $tax = 0;
            return [number_format($tax, 2, '.', ''), number_format($afterTaxAmount + $tax, 2, '.', '')];
        } elseif ($afterTaxAmount <= 3360) {
            $tax = round(($afterTaxAmount - 800) / 4, 2);
            // $tax = number_format(($afterTaxAmount - 800) / 4, 2, '.', '');
            return [number_format($tax, 2, '.', ''), number_format($afterTaxAmount + $tax, 2, '.', '')];
        } elseif ($afterTaxAmount <= 21000) {

            $tax = round(0.16 * $afterTaxAmount / 0.84, 2);

            return [number_format($tax, 2, '.', ''), number_format($afterTaxAmount + $tax, 2, '.', '')];
        } elseif ($afterTaxAmount <= 49500) {

            $tax = round((0.24 * $afterTaxAmount - 2000) / 0.76, 2);

            return [number_format($tax, 2, '.', ''), number_format($afterTaxAmount + $tax, 2, '.', '')];
        } else {

            $tax = round((0.32 * $afterTaxAmount - 7000) / 0.68, 2);

            return [number_format($tax, 2, '.', ''), number_format($afterTaxAmount + $tax, 2, '.', '')];
        }
    }


    /**
     * 获取项目劳务支付税后总金额
     *
     * @Author hechengwei
     * @email chichiooo@sina.com
     * @DateTime 2024-04-30
     * @param [type] $projectId  项目id
     * @return void
     */
    public static function getProjectAfterTaxAmount($projectId)
    {
        $amount = ProjectAgreement::where(['project_id' => $projectId, 'pay_status' => 2])->sum('fee_type_value');
        return number_format($amount, 2, '.', ',');
    }

    /**
     * 获取项目劳务支付总人次
     *
     * @Author hechengwei
     * @email chichiooo@sina.com
     * @DateTime 2024-04-30
     * @param [type] $projectId
     * @return void
     */
    public static function getProjectNumberOfPeople($projectId)
    {
        return ProjectAgreement::where(['project_id' => $projectId, 'pay_status' => 2])->count();
    }
}
